package com.ruoyi.jpbi.controller.jianshe;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.jpbi.domain.jianshe.Fomation;
import com.ruoyi.jpbi.domain.jianshe.Plancontrolcost;
import com.ruoyi.jpbi.domain.jianshe.Planproduct;
import com.ruoyi.jpbi.domain.jianshe.Realproduct;
import com.ruoyi.jpbi.domain.konggu.Emps;
import com.ruoyi.jpbi.service.FomationService;
import com.ruoyi.jpbi.service.RealproductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Auto zh
 * date 2019/10/16
 * 实际产值
 */
@Controller
@RequestMapping("/jianshe/realproduct")
public class RealproductController extends BaseController {

    @Autowired
    RealproductService realproductService;

    @Autowired
    FomationService fomationService;

    private String prefix = "jpbi/jianshe/realproduct";


    /**
     * 跳转分页页面
     */
    @GetMapping()
    public String user() {
        return prefix + "/realproduct";
    }

    /**
     *
     *
     * @param realproduct 条件查询对象
     */
    @RequestMapping("/list")
    @ResponseBody
    public TableDataInfo getRealproductList(Realproduct realproduct, ModelMap mmap) {
        startPage();
        List<Realproduct> realproducts = realproductService.findAllByUser(realproduct);
        return getDataTable(realproducts);
    }

    /**
     * 新增
     */
    @GetMapping("/add")
    public String add(ModelMap mmap) {
        mmap.put("fomation", fomationService.findAllFomation(new Fomation()));
        return prefix + "/add";
    }

    /**
     * 新增实际产值
     *
     * @param realproduct
     * @return
     */
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult add(@Validated Realproduct realproduct) {
        return toAjax(realproductService.insertRealproduct(realproduct));
    }


    /**
     * 修改
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        mmap.put("realproduct", realproductService.findAllById(id));
        mmap.put("fomation", fomationService.findAllFomation(new Fomation()));
        return prefix + "/edit";
    }

    /**
     * 修改计划产值
     *
     * @param realproduct
     * @return
     */
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult edit(@Validated Realproduct realproduct) {
        return toAjax(realproductService.updaterealproduct(realproduct));
    }

    /**
     *删除计划产值
     * @param ids
     * @return
     */
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(realproductService.deleteRealproductByIds(ids));
    }
}
